package com.xiao.controller;

import com.xiao.pojo.Article;
import com.xiao.service.ArticleService;
import com.xiao.service.ESService;
import com.xiao.uitl.es.ESUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class IndexController {
    @RequestMapping("/")
    public String index(){
        return "hello world";
    }

    @Autowired
    ArticleService articleService;

    @Autowired
    ESService esService;

    @GetMapping("/getAllArticle")
    public List<Article> getArticleById(){

        List<Article> allArticle = articleService.getAllArticle();

        return allArticle;
    }

    @GetMapping("/ESInit")
    public String ESInit() throws IOException {
        String init = esService.ESInit();
        return  init;
    }

    @GetMapping("/query/{keyword}")
    public String  queryArticle(@PathVariable( "keyword") String keyword) throws IOException {
        return esService.search(keyword);
    }

}
